/**
 * @param {number[]} flowerbed
 * @param {number} n
 * @return {boolean}
 */
var canPlaceFlowers = function(flowerbed, n) {
     let count = 0;
    for (let i = 0; i < flowerbed.length; i++) {
        if (flowerbed[i] === 0) {
            const prev = i === 0? 0 : flowerbed[i - 1];
            const next = i === flowerbed.length - 1? 0 : flowerbed[i + 1];
            if (prev === 0 && next === 0) {
                flowerbed[i] = 1;
                count++;
                if (count >= n) {
                    return true
                }
            }
        }
    }
    return count >= n

};
console.log(canPlaceFlowers([1,0,0,0,1],1));
